package com.example.QQ;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;


public class ServerThread extends Thread {
    private Socket socket= new Socket();
    Controller h;
    String message;

    public ServerThread(Socket socket,Controller hellow) {
        this.socket = socket;
        this.h=hellow;
    }
    public ServerThread(String message){
        this.message = message;
    }

    public void run(){
        String m;
        try{
            OutputStream os = socket.getOutputStream();
            System.out.println(message);
           // os.write(message.getBytes());
            InputStream is = null;
            is = socket.getInputStream();
            byte[] bytes = new byte[1024];   //定义比特数组存储比特流
            int len = is.read(bytes);
            m = new String(bytes, 0, len);  //将比特流转化为字符
            h.test(m);
            socket.close();
        } catch (IOException ex) {
            System.out.println("Server exception: " + ex.getMessage());
            ex.printStackTrace();
        }

    }
}


